﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace TestManagerClient.Pages
{
    public partial class TestsManage : Page
    {
        List<string> TestsListAll = new List<string>();
        List<string> TestsList = new List<string>();
        List<string> CoursesList = new List<string>();
        public TestsManage()
        {
            InitializeComponent();

            titleTextBlock.Text = "Zarządzaj Testami";
            TestsDrukujButton.IsEnabled = false;
            TestsUsunButton.IsEnabled = false;

            TestsList.Add("Test 1");
            TestsList.Add("Test 2");
            TestsList.Add("Test 3");
            TestsListBox.ItemsSource = TestsList;

            TestsListAll.Add("Test 1");
            TestsListAll.Add("Test 2");
            TestsListAll.Add("Test 3");

            CoursesList.Add("Wszystkie Kursy");
            CoursesList.Add("Kurs 1");
            CoursesList.Add("Kurs 2");
            CoursesList.Add("Kurs 3");
            CoursesListBox.ItemsSource = CoursesList;

            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
            InformationDisplay.HideError(errorGrid, errorTextBlock);
        }

        #region Metody obsługujące przyciski zamknięcia informacji

        private void closeNotificationGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
        }

        private void closeWarningGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideWarning(warningGrid, warningTextBlock);
        }

        private void closeErrorGridButton_Click(object sender, RoutedEventArgs e)
        {
            InformationDisplay.HideError(errorGrid, errorTextBlock);
        }


        private void Tests_Selected(object sender, RoutedEventArgs e)
        {
            if (TestsListBox.SelectedItem != null)
            {
                TestsDrukujButton.IsEnabled = true;
                TestsUsunButton.IsEnabled = true;
            }
            else
            {
                TestsDrukujButton.IsEnabled = false;
                TestsUsunButton.IsEnabled = false;
            }

        }

        private void Courses_Selected(object sender, RoutedEventArgs e)
        {

            if (CoursesListBox.SelectedIndex == 0)
            {
                TestsList.Clear();
                TestsListBox.ItemsSource = TestsListAll;
            }

            if (CoursesListBox.SelectedIndex == 1)
            {
                TestsList.Clear();
                TestsList.Add("Test 1");
                TestsListBox.ItemsSource = TestsList;
            }

            if (CoursesListBox.SelectedIndex == 2)
            {
                TestsList.Clear();
                TestsList.Add("Test 2");
                TestsListBox.ItemsSource = TestsList;
            }

            if (CoursesListBox.SelectedIndex == 3)
            {
                TestsList.Clear();
                TestsList.Add("Test 3");
                TestsListBox.ItemsSource = TestsList;
            }

            TestsListBox.Items.Refresh();
        }


        private void TestsGenerujButton_Click(object sender, RoutedEventArgs e)
        {
            if (Memory.notificationShown)
            {
                InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            }
            else
            {
                InformationDisplay.ShowNotification("Wygenerowano nowy test.", notificationGrid, notificationTextBlock);
            }

            TestsListAll.Add("Test " + (TestsListAll.Count+1));
            TestsListBox.ItemsSource = TestsListAll;
            TestsListBox.Items.Refresh();
        }

        private void TestsDrukujButton_Click(object sender, RoutedEventArgs e)
        {
            if (Memory.notificationShown)
            {
                InformationDisplay.HideNotification(notificationGrid, notificationTextBlock);
            }
            else
            {
                InformationDisplay.ShowNotification("Drukowanie: " + TestsListBox.SelectedItem + "." , notificationGrid, notificationTextBlock);
            }
        }

        private void TestsUsunButton_Click(object sender, RoutedEventArgs e)
        {
            if (Memory.warningShown)
            {
                InformationDisplay.HideWarning(warningGrid, warningTextBlock);
            }
            else
            {
                InformationDisplay.ShowWarning("Usuwanie: " + TestsListBox.SelectedItem + "." , warningGrid, warningTextBlock);
            }
        }

        #endregion
    }
}
